Skip to content

Five more functions at 100%: InGameMenu MainButtons, Roundtable handler, BuySell, UpdateGhost and UpdateHopsFarmer - #416

Merged
gynt merged 7 commits into
sourcehold:mainfrom
kotijekriv:reimpl/round15-units-100
Nov 24, 2026
Merged

gynt merged 7 commits into
sourcehold:mainfrom
kotijekriv:reimpl/round15-units-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Five more functions at 100%, with no header changes. Three are UI functions from our draft #328, and two are Map::Units functions from gynt's units branch reimpl/map-units-updatefunctions (his draft #204), by way of our unpushed units dev branches. All five start from gynt's drafts; each commit cites the drafts it builds on and credits him as co-author. Two of them count as 100% under the rule gynt set in #414 (a function whose only difference is register allocation), and for those the raw reccmp number and the evidence are below.

Function Address Before After
InGameMenu::MenuItemRenderFunction_InGameMenu_MainButtons 0x004643F0 our draft #328, 49.0% (ee10c60); gynt's 47.63% (616eb44; 57.73% at 793ac41) 100.0%, under /GL
Roundtable::MenuItemActionHandler_Roundtable_Main 0x004AEA50 our draft #328, 71.2% (15884ad); gynt's 67.08% (a04df2a) 100.0%, under /GL
BuildingAndStatusMenu::MenuItemActionHandler_BuildingAndStatusMenu_BuySellMenuButtonsAndHands 0x00467040 our draft #328, 93.3% (60ea82a); gynt's 83.81% (30ace91) 100% per #414 (reccmp 93.9%)
Units::UpdateGhost 0x00543B80 gynt's draft 60.35% (e248d10; 52.63% at 9fd4871) 100.0%, under /GL
Units::UpdateHopsFarmer 0x00552F80 gynt's draft 50.99% (4c7f4b4) 100% per #414 (reccmp 99.7%), under /GL

Measured.

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.
  • The three UI functions: an all-on build on main f489b72 (2,442 functions): MainButtons and the Roundtable handler 100.0% raw and normalised, BuySell 93.9% raw. The only main function that moved was InitBlendFilterArraysUnk, normalised 95.0% to 100.0% (97.9% raw both times). The review fixes since that build compile to the same code.
  • The two units: a build of main's whole /GL list plus the new lines, every resolver of those files on: UpdateGhost 100.0%, UpdateHopsFarmer 99.7%, its three callees 100.0%, nothing else moved.
  • Full build: main f489b72 with this branch and the other ready PR's branch, against a full build of main alone, every function resolver that has a .cpp switched on (2,449 functions against 2,439). All five read as above, and so do the /GL callees: Hops', isAIPlayer, getPictureNumberInGm, and Ghost's hasUnitReachedDestination and makeUnitStopWalkingByClearingPathProgressState. No function on main reads lower. InitBlendFilterArraysUnk reads higher normalised (95.0 to 100.0, raw unchanged), as with this branch alone. UI::Menu::handleMenuItems and Constructor_Menu show the known 0x11000000 naming artefact in the larger build: their instructions are the same, reccmp names the constant after a symbol of our DLL that sits at that address, and both read 100 with this branch alone. MapEditorLandscaping's GeneralButtons handler, which doesn't compile on main since the last sync, was left out (Reimplement 88 Map::TileMapState functions at 100% #366 changes it). That build had Hops before its last style pass and with UpdateWorker_ConsiderTakingABreakUnk on the list; the final Hops reads the same 0.9971 in quick_diff, and that callee was dropped from the list because it made no difference.
  • This branch's head alone (2c82df2), all-on build, against main f489b72 (3458fea only adds files under tools/): MainButtons, the Roundtable handler and UpdateGhost read 100.0% raw and normalised, UpdateHopsFarmer 99.7% (90.9% normalised) and BuySell 93.9% (85.9% normalised), with the same differing lines as described below. No function on main reads lower, apart from the 0x11000000 naming artefact on handleMenuItems and Constructor_Menu.
  • Please measure with both resolver switches on (the Globals and the function resolvers), as our numbers are. With its own resolver off, MainButtons reads 83.8% under /GL: nothing takes its address then, so LTCG gives it a private calling convention and drops the load of its argument.
  • Checks: openshc-pr-fix finds nothing to change, and openshc-pr-check gives 0 ERROR.
  • Not run in game.

The two at 100% per #414

The maintainers haven't settled this on #414: gynt set the rule, and TheRedDaemon wrote that he'd accept such functions for now as non-100%. If the status lines should carry the raw numbers (93.9% and 99.7%) instead, say so and we'll change them.

  • BuySell, reccmp 93.9%: ten line pairs differ. In eight only the register names differ: the two imul ..., 0x39f4 player-index computations use ecx and edx the other way round, and one load and one store use edx where the original has eax. The other two are jnes whose displacement is one byte off, because the original's mov [global], eax takes eax's shorter moffs encoding. Those two displacements are why reccmp's own register-swap check (effective) doesn't pass it yet. Same instruction count, same mnemonics in the same order, same memory operands. diff_triage's register-blind ratio is 1.000 (0.859 raw).
  • UpdateHopsFarmer, reccmp 99.7%: one hunk, at 0x005537BD. The original pushes the owner for getBuildingThatCanStoreThisResource with movsx ecx, [owner]; push ecx, ours with eax: the same two instructions and memory operand. Owner locals, int or short casts, and reading it through unitID or the slot all tie or lose, and a symbol-count sweep (0 to 95 dummy typedefs) reads the same at every count.

What got them to 100%

  • MainButtons: rewritten from the binary, with gynt's draft for the names. The original keeps the button's data pointer in ecx across getPictureNumberInGm (0x004630B0), which only LTCG can know is safe, so it needs /GL; without it the zero, the one and the picture offset land in other registers (80.8%).
  • Roundtable handler: from the binary. The seats come from DAT_RoundTableOrderArray (the decompiler had mapSendRequestStatePerPlayer + button + 26), the group numbers are char reads into ints, the highest group is a plain loop over players 1 to 8 that MSVC unrolls into the original's eight copies, and the buttons after the seat logic are an if chain with returns. Under /GL, reading the chosen lord's seat before the target's gives eax and ecx the original's roles. 87.2% without /GL in every form.
  • BuySell: what is left is register allocation only (above). Two scratch-register choices, other source shapes, a plain member call and /GL all tie or lose (/GL drops it to 80.2%).
  • UpdateGhost: owner is read once at the top through DAT_CurrentUnitSlotID::instance into an int const local, as the original keeps it in ecx up to findNextReachableDefensiveBuildingForPlayer. hasUnitReachedDestination and the final makeUnitStopWalkingByClearingPathProgressState get the slot, and in US_IDLEUnk everything from the destinationNeeded store after the timeGetTime test indexes units[] through it, as the original reads the slot again after those calls.
  • UpdateHopsFarmer: every unit access goes through the slot with the worker-helper callees visible, the states are one else-if chain, and a block-level quick_diff search put the storage lookup and addResourceToStockpile back on unitID. In the delivery state, the can-store and reachable-storage paths are the then-arms of their tests.

Behaviour fixed compared with the drafts

  • MainButtons: in the barracks and the mercenary post the original greys the buttons above -10 except the scribe (71) and -4; the draft greyed those at -10 and below. The greys of -1, -5 and -6 set the flags and go on to the draw, so the button is still drawn; the draft returned at once for -1 and one -5 case.

Lines added to cmake/compiler-flags-gl.txt

  • MenuItemRenderFunction_InGameMenu_MainButtons.cpp: 100.0% with it, 80.8% without. getPictureNumberInGm is on main's list already.
  • MenuItemActionHandler_Roundtable_Main.cpp and isAIPlayer.cpp: 100.0% with them, 87.2% without. Only isAIPlayer has to be visible.
  • UpdateGhost.cpp: 100.0% with it, 49.3% without, as hasUnitReachedDestination and makeUnitStopWalkingByClearingPathProgressState (both on main's list) have to be visible.
  • UpdateHopsFarmer.cpp and three callees it needs visible: ComputeGoodsProduced (quick_diff without it 0.9599), IncrementAndOptionalUpdateAVValueRelated (0.8182) and SetStateToFreetimeWalking (0.9899); with none of them on the list Hops reads 0.5950. All three are 100% on main, stay 100.0% on the list, and no other file on the list calls them. UpdateWorker_ConsiderTakingABreakUnk made no difference and stays off.

Kept as they are

  • MainButtons: the GM_CRUSADER_TUTORIAL || next to the != GM_CAMPAIGN_MISSION tests, and the inner != GM_SIEGE_THAT that repeats the outer one, look redundant, but the original makes both compares (0x004644AC and 0x0046459F). isSkirmishTrail != TRUE stays because the original compares the flag with 1.
  • Roundtable handler: it reads the seats again rather than keeping them, and clears the state only when it is set, as the original does.
  • UpdateHopsFarmer: the (char) byte-table reads and the (short) operands and stores, as in main's setFacingDirectionToward*.

What some placeholders hold

  • DAT_00df423c: the chosen lord's seat at the round table.
  • INT_00df4244: set when that seat is clicked again.
  • DAT_00df4240 / DAT_00df4298: the rat's / the sultan's genie line has been played (BOOLEnum candidates).
  • DAT_GameCore.field_0x6c: greys button -5 in campaign missions.
  • farmGrowState: holds the farmer's next UnitState (3 or 5), not a grow state.

Proposed, not changed here

  • An enum for PlayerData::storageMarketFailState, whose values 1 to 10 BuySell sets (the market's failure messages).
  • Two numbers without a BuildMenuTabType value: MainButtons compares the open tab with 48, which is BuildingsAndStatusMenuTabType::BASMTT_STOCKS, so the source reads it through activeMenuTab.tabType; and the 47 at MainButtons :122 (DAT_MenuOptionsActionParameter == 47) has no enum at all.
  • char for byte fields read as signed: Unit::disappearFadeAlphaCountdown and the AnimationFrameData frame tables are byte in the headers, but the original compares them as signed. As char the casts could go.

Three functions leave #328

  • InGameMenu::MenuItemRenderFunction_InGameMenu_MainButtons (0x004643F0)
  • Roundtable::MenuItemActionHandler_Roundtable_Main (0x004AEA50)
  • BuildingAndStatusMenu::MenuItemActionHandler_BuildingAndStatusMenu_BuySellMenuButtonsAndHands (0x00467040)

#328 gets one commit that removes their three .cpp files and puts their status lines back to main's (5ef28e7). The two units were never in our open drafts.

Other PRs

🤖 Generated with Claude Code

kotijekriv and others added 7 commits November 17, 2026 22:12
MenuItemRenderFunction_InGameMenu_MainButtons (0x004643F0, next commit) only matches with link-time code generation.
The original keeps the button's data pointer in ecx across ButtonGmData::getPictureNumberInGm (0x004630B0), which
leaves ecx alone, and reads the button's gm ID through it after the call; MSVC can only do that with both functions
under /GL. getPictureNumberInGm is already in this list on main.

MainButtons measures 100.0 with /GL (reccmp, all-on build on main f489b72: the Globals and every finished function
resolver on, so both functions' resolvers too). On main 3416498 it measured 80.8 without /GL, and 83.8 under /GL
with MainButtons' own resolver off: nothing then takes its address, and LTCG drops the load of its argument.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_InGameMenu_MainButtons, rewritten from the binary with gynt's draft for the names
(e6a4dba, 7f2191d and b9a9e27 on his fork's reimpl/UI-MenuItems, 48.75% there; 793ac41 at 57.73% and
616eb44 at 47.63% on his reimpl/UI-MenuItems-development, 616eb44 being his newest reimplement commit on the file)
and our mechanical pass of it in sourcehold#328 (ee10c60, 49.0%; quick_diff 0.6164 on main). The function leaves sourcehold#328 with
this commit.

reccmp 100.0 (normalized 100.0) in an all-on build on main f489b72 under /GL (the cmake commit before this one),
which has its function resolver and getPictureNumberInGm's (0x004630B0) on; 80.8 without /GL (main 3416498). The original keeps the button's data pointer
in ecx across that call, which only LTCG can know is safe; without it the pointer has to survive the call some other
way, and the zero, the one and the picture offset go to ebx, ebp and edi in another order than the original's.

Fixes against the draft:
- In the barracks and the mercenary post the original greys the buttons above -10 but the scribe (71) and -4; the
  draft greyed those at -10 and below (616eb44 turned the bound round).
- The greys of -1, -5 and -6 set the flags and go on to the build-menu test and the draw, so the button is still drawn;
  the draft returned at once for -1 and for one -5 case.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_Roundtable_Main (0x004AEA50, next commit) only matches with link-time code generation. It calls
GameSynchronyState::isAIPlayer (0x004010B0) for each seat, and isAIPlayer changes only eax; with both under /GL MSVC
knows that, and gives the handler the original's registers (eax for the chosen lord's seat, ecx for the button where
the seats are read). Without /GL the handler reads 87.2 in every source form tried.

isAIPlayer is 100% on main with its function resolver on and stays at 100.0 under /GL (reccmp, all-on build on main
f489b72, built with the handler). It is the only callee the handler needs there: on main 3416498, with the
handler's other five finished callees (resetMouseState2, nextRandomNumber1, playWAVSFX, scheduleSFXVariation,
shouldSoundXNotBePlaying) also under /GL, the result was the same 100.0. No other file in this list calls isAIPlayer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_Roundtable_Main, from gynt's draft (c53b2b9 and 18ddd79 on his fork's reimpl/UI-MenuItems,
61.09% there; 65013b9 at 66.46% and a04df2a at 67.08% on his reimpl/UI-MenuItems-development, a04df2a being
his newest reimplement commit on the file), our mechanical pass of it in sourcehold#328 (15884ad, 71.2%) and our own rewrite
from the binary at 87.2% (local, never pushed). The function leaves sourcehold#328 with this commit.

reccmp 100.0 (normalized 100.0) in an all-on build on main f489b72 under /GL (the cmake commit before this one),
which has its function resolver and isAIPlayer's on; 87.2 without /GL (main 3416498).

From the binary: the chosen lord's and the target's seats are read from DAT_RoundTableOrderArray (the decompiler had
them as mapSendRequestStatePerPlayer + button + 26), the group numbers are char reads into ints with no casts, the
highest group in use is a plain loop over players 1 to 8 (MSVC unrolls it into the original's eight copies, as it does
the group count of button 100), the new group is one local stored twice, and the buttons after the seat logic are an
if chain with returns. The last difference under /GL was which of eax and ecx held the chosen seat and the button: the
original's comes from reading the chosen lord's seat before the target's.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_BuildingAndStatusMenu_BuySellMenuButtonsAndHands, from gynt's draft (7cbb7b8 and fb51a06
on his fork's reimpl/UI-MenuItems, 83.17% there; 30ace91 at 83.81% on his reimpl/UI-MenuItems-development) and
our pass of it in sourcehold#328 (74bdd12, 83.8%; 60ea82a, 93.3%). The function leaves sourcehold#328 with this commit.

Register allocation only, per sourcehold#414, so the status line records 100.0. reccmp's own score is 93.9 in an all-on build
on main f489b72, and diff_triage's register-blind ratio is 1.000 (0.859 before renaming registers): every
remaining difference is a register name. Ten line pairs differ. In eight, the two `imul ..., 0x39f4` player-index
computations use ecx and edx the other way round and one load and one store use edx where the original uses eax.
The other two are jumps one byte off, because the original's `mov [global], eax` takes the shorter moffs encoding
that edx has not. Same instruction count, same mnemonics in the same order, same memory operands.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Units::UpdateGhost, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (9fd4871 at 52.63%,
e248d10 at 60.35%), under /GL:
- owner is read once at the top through DAT_CurrentUnitSlotID::instance, into an int const local that the
  nonInteractiveCitizenCountUnk increment and findNextReachableDefensiveBuildingForPlayer's first argument use: the
  original loads it before the stateBasedSpeed store and keeps it in ecx up to that call (quick_diff with the /GL
  callees in the unit 0.9568 -> 0.9784; the local read through unitID 0.7071, a short local 0.5833);
- makeUnitStopWalkingByClearingPathProgressState at the end and hasUnitReachedDestination get the slot, and in
  US_IDLEUnk every statement from the destinationNeeded store after the timeGetTime test to the end of the state
  indexes units[] through it, as the original reads the slot again after playSFXAtLocation and timeGetTime. unitID
  is then not live across those calls, and the timeGetTime pointer gets esi as in the original (0.9424 -> 0.9568;
  starting one statement later 0.9429). The other statements use unitID or the slot as a greedy quick_diff search
  picked them one statement per step;
- states 108 and 2 are US_UNKNOWN_108 and US_STATE_2Unk;
- three stores in blocks that otherwise use unitID stay through the slot (no comment, per gynt on sourcehold#393): the
  US_IDLEUnk state store in US_DETERMINE_NEXT_STATEUnk (through unitID: quick_diff 0.9784 -> 0.9640), the
  field_0x30_animRelated store in US_MELEE_ATTACK (0.9712) and the clamp to 32 in state 2 (0.9712);
- compiler-flags-gl.txt lists UpdateGhost.cpp: 100% with the line, 49.3% without it, as hasUnitReachedDestination
  and makeUnitStopWalkingByClearingPathProgressState, both on main's list, have to be visible.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Units::UpdateHopsFarmer, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (4c7f4b4 at 50.99%),
through an earlier version on our dev branch at 99.7%: every unit access goes through
DAT_CurrentUnitSlotID::instance with the worker-helper callees visible, the states form one else-if chain, and a
block-level quick_diff search put the storage lookup back on unitID; the solitary-or-not goods amount is an if/else
with the call in each arm; in the delivery state the can-store path is the then-arm of canBuildingStoreTheAmount
and the reachable-storage path the then-arm of buildingIsAccessible. Kept forms (quick_diff with the /GL
callees in the unit; the first and last with a one-line why, the slot indexing without, per gynt on sourcehold#393):
- the delivery state's else arm reads the slot into unitID again, as the original does (without it 0.9949);
- setDestinationForUnit in the walk-to-field state takes unitID, as the original keeps the slot across
  UpdateWorker_ConsiderTakingABreakUnk there (through the slot 0.9864);
- ownFarm reads workplaceBuildingID_1 again after the calls next to farm (reusing farm 0.9272).
Style on top, all the same code (0.9971 before and after): DNE_UNKNOWN_2 for (DestinationNeededEnum)2 and no using
line, no casts on the stores into short fields and on the coordinate operands, BOOLEnum results tested by
truthiness, ++/--, int const storage, no unused BOOLEnum include.

compiler-flags-gl.txt gets UpdateHopsFarmer.cpp and the three callees it needs visible, each 100% on main and
called by no other file on the list: ComputeGoodsProduced (quick_diff without it 0.9599),
IncrementAndOptionalUpdateAVValueRelated (0.8182) and SetStateToFreetimeWalking (0.9899); with no callee bodies at
all, i.e. off the list, 0.5950. UpdateWorker_ConsiderTakingABreakUnk makes no difference (0.9971 without it) and
stays off. reccmp in a build of main's whole /GL list with every resolver of those files on: UpdateHopsFarmer
99.7%, the three callees 100.0%, nothing else moved.

The one difference left is register allocation only (sourcehold#414): the owner pushed for
getBuildingThatCanStoreThisResource is loaded into eax where the original uses ecx, the same two instructions and
memory operand. Owner locals, an int or short cast, and reading it through unitID or the slot all tie or lose; a
symbol-count sweep (0..95 dummy typedefs, after the includes and at the top) reads 0.9971 at every count.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gynt
gynt added this pull request to the merge queue Nov 24, 2026
Merged via the queue into sourcehold:main with commit d3d1179 Nov 24, 2026
5 checks passed
gynt pushed a commit to kotijekriv/OpenSHC that referenced this pull request Nov 24, 2026
…old#416, sourcehold#433 and sourcehold#438 (sourcehold#491)

sourcehold#416, sourcehold#433 and sourcehold#438 put six callers on cmake/compiler-flags-gl.txt after sourcehold#398 without an entry here: InGameMenu's
MenuItemRenderFunction_InGameMenu_MainButtons and Roundtable's MenuItemActionHandler_Roundtable_Main (sourcehold#416),
UpdateGhost (sourcehold#416), UpdateFireWatch and UpdateHunterDog (sourcehold#433), and UpdateCageDog (sourcehold#438). Each gets an entry at its
address, its callees in address order. The /GL lines stay as they are.

Each edge is measured as sourcehold#398's were: the caller's file compiled with the callee files in its unit, against the
caller alone, quick_diff on main 7c2e4d6 with every function resolver that has a .cpp and every struct resolver
on. The callees tried are the caller's /GL-listed callees below its address. A callee is listed when it raises the
caller's ratio on its own, or when leaving it out of the full set lowers it; the listed set reads what the full set
reads.

- MainButtons: 0.8217 alone, 1.0000 with ButtonGmData::getPictureNumberInGm.
- Roundtable_Main: 0.9391 alone, 0.9984 with GameSynchronyState::isAIPlayer.
- UpdateFireWatch: 0.3834 alone, 0.9980 with checkIfCitizenUnitIsAliveBasedOnState and hasUnitReachedDestination,
  the same as with all four of its /GL callees; leaving one of the four out reads 0.7178
  (checkIfCitizenUnitIsAliveBasedOnState) and 0.6606 (hasUnitReachedDestination).
  makeUnitStopWalkingByClearingPathProgressState and commitUnitLocation change nothing.
- UpdateGhost: 0.5214 alone, 0.9712 with hasUnitReachedDestination. makeUnitStopWalkingByClearingPathProgressState
  changes nothing.
- UpdateHunterDog: 0.3336 alone, 1.0000 with its four callees and with all five of its /GL callees; leaving one of
  the five out reads 0.9944 (makeUnitStopWalkingByClearingPathProgressState), 0.7283
  (checkIfCitizenUnitIsAliveBasedOnState), 0.9298 (hasUnitReachedDestination), 0.9114
  (hasTunnelerNotFinishedDigging). resumeMovementIfNoAttackTarget changes nothing.
- UpdateCageDog: 0.2829 alone, 1.0000 with its four callees and with all seven of its /GL callees; leaving one of
  the seven out reads 0.8651 (makeUnitStopWalkingByClearingPathProgressState), 0.7162
  (checkIfCitizenUnitIsAliveBasedOnState), 0.4142 (hasUnitReachedDestination), 0.9949 (tryAttackUnitID, which sourcehold#438
  added to the /GL list for it). buildingIsAccessible, resumeMovementIfNoAttackTarget and commitUnitLocation change
  nothing.

sourcehold#473 and sourcehold#475 put UpdateSiegeTent and UpdateHorseArcher_DoShooting on the /GL list; neither calls a /GL-listed
function, so neither gets an entry. UpdateHorseArcher calls UpdateHorseArcher_DoShooting, which sits below it, but
reads worse with its body (0.9929 with hasUnitReachedDestination, 0.9906 with both), so its entry stays as it is.

With every .cpp of main as the build list, cmake/function-visibility-units.py now makes 24 units holding 116 source
files (108 before): the six callers, tryAttackUnitID and makeUnitStopWalkingByClearingPathProgressState join the
existing groups. No internal names clash, and the 13 names it skips are the ones it skipped before.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Wilps93 pushed a commit to Wilps93/OpenSHC that referenced this pull request Nov 26, 2026
…rk (sourcehold#495)

TheRedDaemon asked on sourcehold#417 for a lower percentage, or the function taken out, where a match is short of 100 for a
known reason, and a remark in the status file either way. For our functions on main whose line says 100.0% but which
read lower in all-on full builds of main 71b70de and d348c31 (1f87a13 changes none of their files or headers):

- three read 100% until a header sync on main moved a register tie that depends on the declaration count (source
  unchanged): ShareGameSeedAndMultiplayerSettingsAndStartGame and UpdateUnitLossSpeechFeedback (6033692),
  LaunchSinglePlayerGameUnk (48f7e94). They get the measured % and a remark that says so;
- two differ in register choice only (sourcehold#416, recorded as 100% per sourcehold#414): they get the measured % and a "register
  choice only" remark in the form sourcehold#417 uses;
- ten differ only in names (call targets, loop-end and folded addresses, a type in a resolver's name). They stay at
  100.0% under AGENTS.md's rule and get the remark their line was missing.

Status file only.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv added a commit to kotijekriv/OpenSHC that referenced this pull request Nov 29, 2026
…gynt's units branch, under /GL (100%) (sourcehold#512)

* reimplement: SHC_3BB0A8C1_0x00566750 100.0% Reimplemented

Units::UpdatePriest, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (b389b78 at 63.25%,
after 525a6eb at 57.72%), through our dev branch (99.9% on main before sourcehold#378). Against the dev branch's file:
- the walk to the unit to bless reads the unit through the slot global from its first line, call arguments
  included, with no assignment to `unitID` in it. changeDestinationByAmount, which sourcehold#378 brought to main's /GL
  list, is then visible to the compiler and leaves the slot alone;
- `animationSheetFrameOffset = 1` stands in front of `field_0x30_animRelated = 16` in both arms of that walk;
- `destinationNeeded` at the end of the preaching state goes through the global.
The rest is the dev branch's: `stateBasedSpeed = 0` written in front of the priest count, the campfire and inn
walks through the global, and one call argument through the global for the registers at the top.
The states 2, 3, 9, 11, 108 and 121 use UnitState's names, the fade's direction is written -2 as in main's
UpdateMerchant, and nothing is cast to short on its way into a short field.

compiler-flags-gl.txt gets UpdatePriest.cpp. IncrementAndOptionalUpdateAVValueRelated.cpp, a callee the unit has to
see, is on main's list already (sourcehold#416).

Real builds on main 655adce, every listed file's function resolver and all data resolvers on. A small one: main's
/GL list plus this branch's four lines (main's UpdateGateHouseLarge and UpdateGateHouseSmall left out: they don't
compile on 655adce), with an earlier spelling of UpdatePikeman. A full one: every file at this branch's head
against main alone (main's 12 files that don't compile on 655adce left out). UpdatePriest reads 100.0% raw and
normalised in both, with no differing line in the small one, and nothing on main reads lower in the full one.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x00541A30 100.0% Reimplemented

Units::UpdateMerchantHorse, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (4b7d935 at
46.84%, after e103100 at 41.35%), through our dev branch (99.1% on main before sourcehold#378). Against the dev branch's
file, one store: `updateTickTracker = 0`, the last store in front of resetUnitMovementState, goes through the slot
global. With commitUnitLocation's callees visible (setupUnitSharingTileIDs, which sourcehold#378 brought to main's /GL list,
and setupUnitSharingCurrentTilePosition), the compiler then sets up resetUnitMovementState's argument above the
last store only, as the original does. The rest is the dev branch's, with one call argument through the global for
the registers at the top.
The states 2 and 3 use UnitState's names, also where they are stored into cachedState, and the fade's direction is
written -2 as in main's UpdateMerchant.

compiler-flags-gl.txt gets UpdateMerchantHorse.cpp.

Real builds on main 655adce, every listed file's function resolver and all data resolvers on. A small one: main's
/GL list plus this branch's four lines (main's UpdateGateHouseLarge and UpdateGateHouseSmall left out: they don't
compile on 655adce), with an earlier spelling of UpdatePikeman. A full one: every file at this branch's head
against main alone (main's 12 files that don't compile on 655adce left out). UpdateMerchantHorse reads 100.0% raw
and normalised in both, with no differing line in the small one, and nothing on main reads lower in the full one.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x0055F110 100.0% Reimplemented

Units::UpdatePikeman, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (4630f86 at 41.54%),
through our dev branches (99.9% on main before sourcehold#378). The forms that matter:
- `int building = 0;` with the function's locals and no local copy of the unit ID, as in UpdateKnight (sourcehold#444): the
  original's 4 bytes of frame that are never touched and its zero register for a wall;
- the dig-moat block behind setDestinationForUnit reads the unit through the slot global, call argument included.
  With changeDestinationByAmount's body visible (sourcehold#378 brought it to main's /GL list) the compiler knows the call
  leaves the slot alone and stores the dig tile's X and Y in front of the pops, as the original does (0x0055F2AB,
  0x0055F2B2).
The states 2, 3 and 108 use UnitState's names; 105 and 124 have none on main and keep their casts. State 0's
choice between 2 and IDLE, the thrust picture's and the damage are if / else (main's style-lint flags a ternary).
The AI's wall-danger test reads `attackInfo.playerInfo[attacker - 1]` (currentPlayerID_OR_attackedPlayerID_OR_one
and someMinimumDistance) and `SEC_PathfindingCostTileMap1105`, where main's header now has these blocks (they were
raw offsets before); the LogicLayer masks use Logic1's names and the two orientation tests CD_UNSPECIFIED. The hit
sound keeps getBuildingHurtSFXID's result as a HitSoundMaterialInt and compares it with HSM_WOOD and HSM_STONE, as
UpdateArabianSwordsman does. Nothing is cast to short on its way into a short field or on a read of a short layer,
steps by one are ++ / --, and the gate-or-tower test for the damage is a truth test, as in the AI's test below it.
advanceMoatDigProgress and removeMoat return BOOLEnum, but their results stay compared with 1: the original has
`cmp eax, 1` there (0x0055FC1F, 0x0055FE11), and a truth test gives `test eax, eax`.

compiler-flags-gl.txt gets UpdatePikeman.cpp and ViewportRenderState/xyAreValid.cpp, a callee the unit has to see
(100% on main).

Real builds on main 655adce, every listed file's function resolver and all data resolvers on. A small one: main's
/GL list plus this branch's four lines (main's UpdateGateHouseLarge and UpdateGateHouseSmall left out: they don't
compile on 655adce), on this text. A full one: every file, on an earlier spelling of this file that differs only
in names and spellings and gives the same listing, against main alone (main's 12 files that don't compile on
655adce left out). UpdatePikeman and xyAreValid read 100.0% raw and normalised in both, with no differing line
in the small one, and nothing on main reads lower in the full one.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants